<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>

<body>
  <h2>Child页面</h2>
  <button id="btn">给Index页面发消息</button>

  <script>
    let btn = document.getElementById("btn");
    btn.addEventListener("click",()=>{
      window.parent.postMessage("world","*")
    })

    window.addEventListener("message", e => {
      console.log(e.data);
      console.log(e.origin);
    })
  </script>
</body>

</html>